/**
 * @FileName: DateUtils.java
 * @Author
 * @Description:
 * @Date 2016年3月28日 下午3:32:51
 * @CopyRight ZTE Corporation
 */
package cn.hpclub.server.service.ds;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class DateUtils{
    public static SyncParams getLastDayParams(Date date){
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(Calendar.DATE, -1);
        date = calendar.getTime();
        SimpleDateFormat dateFormater = new SimpleDateFormat("yyyy-MM-dd");
        String lastDay = dateFormater.format(date);
        SyncParams params = new SyncParams();
        params.start = lastDay;
        params.end = lastDay;
        params.tag = lastDay.replace("-", "");
        return params;
    }

    public static SyncParams getLastMonthParams(Date date){
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(Calendar.MONTH, -1);

        // 上个月第一天
        calendar.set(Calendar.DATE, 1);
        String firstDay = df.format(calendar.getTime());

        // 上个月最后一天
        calendar.add(Calendar.MONTH, 1);
        calendar.set(Calendar.DATE, 1); // 设置为该月第一天
        calendar.add(Calendar.DATE, -1); // 再减一天即为上个月最后一天
        String lastDay = df.format(calendar.getTime());

        SimpleDateFormat dfMonth = new SimpleDateFormat("yyyyMM");
        SyncParams params = new SyncParams();
        params.start = firstDay;
        params.end = lastDay;
        params.tag = dfMonth.format(calendar.getTime());
        return params;
    }

    public static class SyncParams{
        public String start;
        public String end;
        public String tag;
        public String logTag;

        /**
         * @return
         * @see java.lang.Object#toString()
         */
        @Override
        public String toString(){
            return "[时间范围=" + start + " - " + end + ", 标签=" + tag + "]";
        }

    }
}
